/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import java.awt.Component;
import java.beans.PropertyVetoException;
import java.util.Date;
import java.util.HashMap;
import java.util.logging.Level;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.query.JRHibernateQueryExecuterFactory;
import net.sf.jasperreports.view.JasperViewer;
import org.apache.log4j.Logger;
import org.hibernate.Session;
import pojo.LoaiNguoiDung;
import pojo.NguoiDung;
import util.NewHibernateUtil;
/**
 *
 * @author 0
 */
public class MainGUI extends javax.swing.JFrame {

    /**
     * Creates new form NewJFrame
     */
    private static Logger logger=Logger.getLogger(MainGUI.class);
    public static NguoiDung nguoiDung=new NguoiDung(0, null, new LoaiNguoiDung(4), null, null, null, null, null, null, null, false, null, null);
  //  public static CuaHang cuaHang =new CuaHang(new CuaHang(4));
    
    public MainGUI() {
     //   super("Report view",true,true,true,true);
        initComponents();
        setExtendedState(JFrame.MAXIMIZED_BOTH);
        setBounds(10,10,600,500);
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jMenuItem3 = new javax.swing.JMenuItem();
        tabMain = new org.xnap.commons.gui.CloseableTabbedPane();
        jMenuBar1 = new javax.swing.JMenuBar();
        mnQuanLyNhanVien = new javax.swing.JMenu();
        mnQuanLyCuaHang = new javax.swing.JMenu();
        mnQLSanPham = new javax.swing.JMenu();
        mnQuanLySanPhamCuaHang = new javax.swing.JMenu();
        Report_cuahang = new javax.swing.JMenu();
        ReportSPLIST = new javax.swing.JMenu();
        ReportLoaiSP = new javax.swing.JMenu();
        jMenu1 = new javax.swing.JMenu();

        jMenuItem3.setText("jMenuItem3");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Quản lý chuỗi cửa hàng bán quần áo");
        getContentPane().setLayout(new java.awt.GridLayout(1, 0));
        getContentPane().add(tabMain);

        jMenuBar1.setDoubleBuffered(true);

        mnQuanLyNhanVien.setText("Quản lý nhân viên");
        mnQuanLyNhanVien.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                mnQuanLyNhanVienMouseClicked(evt);
            }
        });
        jMenuBar1.add(mnQuanLyNhanVien);

        mnQuanLyCuaHang.setText("Quản lý cửa hàng");
        mnQuanLyCuaHang.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                mnQuanLyCuaHangMouseClicked(evt);
            }
        });
        jMenuBar1.add(mnQuanLyCuaHang);

        mnQLSanPham.setText("Quản lý sản phẩm");
        mnQLSanPham.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                mnQLSanPhamMouseClicked(evt);
            }
        });
        jMenuBar1.add(mnQLSanPham);

        mnQuanLySanPhamCuaHang.setText("Quản lý sản phẩm cửa hàng");
        mnQuanLySanPhamCuaHang.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                mnQuanLySanPhamCuaHangMouseClicked(evt);
            }
        });
        jMenuBar1.add(mnQuanLySanPhamCuaHang);

        Report_cuahang.setText("Report Cửa Hàng");
        Report_cuahang.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                Report_cuahangMouseClicked(evt);
            }
        });
        jMenuBar1.add(Report_cuahang);

        ReportSPLIST.setText("Report Sản Phẩm");
        ReportSPLIST.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ReportSPLISTMouseClicked(evt);
            }
        });
        jMenuBar1.add(ReportSPLIST);

        ReportLoaiSP.setText("Report Loại Sản Phẩm");
        ReportLoaiSP.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ReportLoaiSPMouseClicked(evt);
            }
        });
        jMenuBar1.add(ReportLoaiSP);

        jMenu1.setText("Report Sản Phẩm Cửa Hang");
        jMenu1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jMenu1MouseClicked(evt);
            }
        });
        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void mnQuanLyNhanVienMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mnQuanLyNhanVienMouseClicked
        try {
            // TODO add your handling code here:
            Component[] components=tabMain.getComponents();
            for(Component component:components){
                if(component instanceof DanhSachNhanVienGUI){
                    tabMain.setSelectedComponent(component);
                    return;
                }
            }
           
            tabMain.add("Quản lý nhân viên", new DanhSachNhanVienGUI());
        } catch (Exception ex) {
            logger.error(new Date().toString(), ex);
        }
    }//GEN-LAST:event_mnQuanLyNhanVienMouseClicked

    private void mnQuanLySanPhamCuaHangMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mnQuanLySanPhamCuaHangMouseClicked
       try{
        Component[] components=tabMain.getComponents();
        for(Component component:components){
            if(component instanceof QLSanPham_CuaHangGui){
                tabMain.setSelectedComponent(component);
                return;
            }
        }
        tabMain.add("Quản Lý Sản Phẩm Của Cửa Hàng", new QLSanPham_CuaHangGui());
       }catch(Exception ex){
           logger.error(new Date().toString(),ex);
       }
    }//GEN-LAST:event_mnQuanLySanPhamCuaHangMouseClicked

    private void mnQuanLyCuaHangMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mnQuanLyCuaHangMouseClicked
        // TODO add your handling code here:
        try{
            Component []components =tabMain.getComponents();
            for(Component component:components){
                if(component instanceof DanhSachCuaHangGui){
                    tabMain.setSelectedComponent(component);
                    return;
                }
            }
            tabMain.add("Danh Sách Cửa Hàng",new DanhSachCuaHangGui());
        }catch(Exception ex){
             logger.error(new Date().toString(), ex);
        }
    }//GEN-LAST:event_mnQuanLyCuaHangMouseClicked

    private void mnQLSanPhamMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mnQLSanPhamMouseClicked
       try{
           Component []comps =tabMain.getComponents();
           for(Component cmpn:comps){
               if(cmpn instanceof DanhSachSanPhamGui){
               tabMain.setSelectedComponent(cmpn);
               return;
               }
           }
           tabMain.add("Quản Lý Danh Sách Sản Phẩm", new DanhSachSanPhamGui());
       }
       catch(Exception ex){
           //logger.error(new Date().toString(), ex.getMessage().toString());
          JOptionPane.showConfirmDialog(this, ex.getMessage());
             
    }//GEN-LAST:event_mnQLSanPhamMouseClicked
    }
    private void Report_cuahangMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_Report_cuahangMouseClicked
        try {       
              
            ReportCuaHang myiReportViewer = new ReportCuaHang("src\\danh sach cua hang.jrxml");
//           
            myiReportViewer.setBounds(0, 0, tabMain.getWidth(), tabMain.getHeight());
            myiReportViewer.setVisible(true);            
            tabMain.add(myiReportViewer);
            myiReportViewer.setSelected(true);
        } catch (JRException ex) {
          //  Logger.getLogger(MainGUI.class.getName()).log(Level.SEVERE, null, ex);
        } catch (PropertyVetoException pve) {
            pve.printStackTrace();
        }
    }//GEN-LAST:event_Report_cuahangMouseClicked

    private void ReportSPLISTMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ReportSPLISTMouseClicked
       try {       
              
            ReportSanPhams myiReportViewer = new ReportSanPhams("src\\Danh sach san pham.jrxml");
           
            myiReportViewer.setBounds(0, 0, tabMain.getWidth(), tabMain.getHeight());
            myiReportViewer.setVisible(true);            
            tabMain.add(myiReportViewer);
            myiReportViewer.setSelected(true);
        } catch (JRException ex) {
          //  Logger.getLogger(MainGUI.class.getName()).log(Level.SEVERE, null, ex);
        } catch (PropertyVetoException pve) {
            pve.printStackTrace();
        }
    }//GEN-LAST:event_ReportSPLISTMouseClicked

    private void ReportLoaiSPMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ReportLoaiSPMouseClicked
        try {       
              
            Report_LoaiSP myiReportViewer = new Report_LoaiSP("src\\Danh Sach Loai San Pham1.jrxml");
           
            myiReportViewer.setBounds(0, 0, tabMain.getWidth(), tabMain.getHeight());
            myiReportViewer.setVisible(true);            
            tabMain.add(myiReportViewer);
            myiReportViewer.setSelected(true);
        } catch (JRException ex) {
          //  Logger.getLogger(MainGUI.class.getName()).log(Level.SEVERE, null, ex);
        } catch (PropertyVetoException pve) {
            pve.printStackTrace();
        }
    }//GEN-LAST:event_ReportLoaiSPMouseClicked

    private void jMenu1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenu1MouseClicked
       try {       
              
            Report_sanpham_cuahang myiReportViewer = new Report_sanpham_cuahang("src\\sanphamtheocuahang.jrxml");
           
            myiReportViewer.setBounds(0, 0, tabMain.getWidth(), tabMain.getHeight());
            myiReportViewer.setVisible(true);            
            tabMain.add(myiReportViewer);
            myiReportViewer.setSelected(true);
        } catch (JRException ex) {
          //  Logger.getLogger(MainGUI.class.getName()).log(Level.SEVERE, null, ex);
        } catch (PropertyVetoException pve) {
            pve.printStackTrace();
        }
    }//GEN-LAST:event_jMenu1MouseClicked
    
    
        
       

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new MainGUI().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenu ReportLoaiSP;
    private javax.swing.JMenu ReportSPLIST;
    private javax.swing.JMenu Report_cuahang;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenu mnQLSanPham;
    private javax.swing.JMenu mnQuanLyCuaHang;
    private javax.swing.JMenu mnQuanLyNhanVien;
    private javax.swing.JMenu mnQuanLySanPhamCuaHang;
    private org.xnap.commons.gui.CloseableTabbedPane tabMain;
    // End of variables declaration//GEN-END:variables
}
